<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<style>
	ul{
	list-style:none;
}
</style>  
<div id="formatParamDiv" style="padding: 20px;">
	 <table cellpadding="5">
	    	<tr class="params hide">
	        	<!-- <td>商品规格信息:</td> -->
	        	
	        </tr>
	    </table>
</div>
<div style="text-align: center;">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitpUpdateParam()">提交修改</a>
</div>
<script>
//生成规格表
$.post("formatParam/getFormatInfoById",{id:$('#goodsData').datagrid('getSelected').gId},function(data){
	  if(data.status == 200 && data.data){
		 var paramData = JSON.parse(data.data.gpParamData);
		 for(var i in paramData){
			 var html = "<td><ul>";
			 var pd = paramData[i];
			 html+="<li><table>";
			 html+="<tr><td style=\"text-align:center\" colspan=\"2\" class=\"group\">"+pd.group+"</td></tr>";
			 for(var j in pd.params){
				 var ps = pd.params[j];
				 html+="<tr><td class=\"param\"><span>"+ps.k+"</span>: </td><td><input value="+ps.v+" class=\"inputId\"  type=\"text\"  type=\"text\"/></td></tr>";
			 }
			 html+="</li></table>";
			 html+= "</ul></td>";
			 $("#formatParamDiv .params").append($(html));
		 }
		 $(".inputId").textbox({
				disabled:false
			}); 
		 
	  }else if(data.status==400){
		  $.messager.alert('错误',data.data,'info');
	  }
  });
  function submitpUpdateParam(){
	//规格数据获取
		 var paramJson = [];//规格数据生成json对象
		$("#formatParamDiv .params li").each(function(i,e){
			var trs = $(e).find("tr");
			var group = trs.eq(0).find("td").text();
			var ps = [];
			for(var i = 1;i<trs.length;i++){
				var tr = trs.eq(i);
				ps.push({
					"k" : $.trim(tr.find("td").eq(0).find("span").text()),
					"v" : $.trim(tr.find("input").eq(1).val())
				});
			}
			paramJson.push({
				"group" : group,
				"params": ps
			});
		}); 
		 
		$.post("formatParam/updateFormatInfoById",{id:$('#goodsData').datagrid('getSelected').gId,formatParam:JSON.stringify(paramJson)},function(data){
			if(data.status == 200){
				$.messager.show({
					title:'成功提示',
					msg:'商品规格数据修改成功',
					timeout:5000,
					showType:'slide'
				});
			}else{
				$.messager.alert('提示',data.data,'info');
			}
		});
  }
</script>